#define _WIN32_WINNT 0x0501
#include "moeutil/net/async_archive_socket.h"


class MyObject
{
public:
	MyObject()
		: mText("MyObjectText"), mNumber(100)
	{
	}


public:
	std::string mText;
	int mNumber;
};

moeutil_serialization_class_no_interfere(MyObject)
template<typename Archive>
void serialise(Archive& ar, MyObject& obj)
{
	ar & obj.mText;
	ar & obj.mNumber;
}

std::vector<std::string*> g_Texts;


typedef moeutil::net::async_archive_socket<tcpsocket> wrap_tcpsocket;

void on_recv(wrap_tcpsocket& sock)
{
	MyObject obj;
	
	{
		wrap_tcpsocket::read_scope rs(sock);
		sock.iarchive() >> g_Texts >> obj;
	}
	for(std::vector<std::string>::iterator it = g_Texts.begin();
		it != g_Texts.end();
		++it)
	{
		std::cout<<*it<<std::endl;
	}
	std::cout<<obj.mText<<"  "<<obj.mNumber<<std::endl;
}

void main()
{
	boost::asio::io_service ioserv;
	tcp_endpoint ep(boost::asio::ip::address::from_string("127.0.0.1"), 4001);

	tcp_acceptor accpt(ioserv, ep); 
	accpt.listen();

	tcpsocket_ptr sock(new tcpsocket(ioserv));
	accpt.accept(*sock);

	wrap_tcpsocket wrapSock(sock);
	wrapSock.observer_recv = on_recv;

	wrapSock.run();
	boost::system::error_code ec;
	ioserv.run(ec);
	std::cout<<ec.message()<<std::endl;

	::system("Pause");
}